﻿using DFGK.IService;
using DFGK.Service;
using DFGK_WMS.Common;
using DFGK_WMS.Model.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.PDA.盘库管理
{
    /// <summary>
    /// 盘库管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "PDA")]
    public class StocktakingOrderDetailsController : BaseController
    {
        private readonly IStocktakingOrderService stocktakingOrderService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="environment"></param>
        /// <param name="stocktakingOrderService"></param>
        public StocktakingOrderDetailsController(IWebHostEnvironment environment, IStocktakingOrderService stocktakingOrderService) : base(environment)
        {
            this.stocktakingOrderService = stocktakingOrderService;
        }

        /// <summary>
        /// 开始盘点
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult StartStocktakingOrder(StocktakingOrderDto m)
        {
            if(m.Id <= 0)
                return Ok(BaseResult.Result("400", "盘点单id有误！"));

            string message = "";
            m.NowUserId = base.BaseGetNowUserId();
            m.NowUserName = base.BaseGetNowUserName();
            bool result = stocktakingOrderService.StartStocktakingOrder(m, out message);
            if (result)
            {
                return Ok(BaseResult.Result(result, "操作成功！", "200"));
            }
            return Ok(BaseResult.Result(result, "操作失败！" + message, "500"));
        }

        /// <summary>
        /// 开始盘点回库
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult StartStocktakingOrders(StocktakingOrderDto m)
        {
            if (m.Id <= 0)
                return Ok(BaseResult.Result("400", "盘点单id有误！"));

            string message = "";
            m.NowUserId = base.BaseGetNowUserId();
            m.NowUserName = base.BaseGetNowUserName();
            bool result = stocktakingOrderService.StartStocktakingOrders(m, out message);
            if (result)
            {
                return Ok(BaseResult.Result(result, "操作成功！", "200"));
            }
            return Ok(BaseResult.Result(result, "操作失败！" + message, "500"));
        }
    }
}
